
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using System.ComponentModel;
using com.binance.client;
using com.binance.client.model.market;
using com.binance.client.model.trade;
using com.binance.client.model.enums;
using com.binance.client.model;

namespace QntPlatform.BinanceApi
{
    public class JFApiClient : ApiClientBase, SyncRequestClient
    {
        public static bool IsVProxySet { get; set; } = false;
        public override string PasswordKey { get; protected set; } = "signature";
        public override string UsernameKey { get; protected set; } = "X-MBX-APIKEY";
        //https://vercel-t.6m.vercel.app/   https://fapi.binance.com http/42.193.122.131:5051
        public override Uri BaseUrl { get; } = new Uri("https://fapi.binance.com");


        public JFApiClient(string apiKey, string secretKey)
        {
            PasswordValue = secretKey;
            UsernameValue = apiKey;
            isVProxy = IsVProxySet;
            if (isVProxy)
            {
                BaseUrl = new Uri("https://vercel-t.6m.vercel.app/_https/fapi.binance.com");
            }
        }
        public AccountInformation account()
        {
            var re = CreateReq("/fapi/v2/account", recvWindow: 15000);
            var re2 = re
             .Get<AccountInformation>();
            return CheckResp(re2);
        }

        private static T CheckResp<T>(RestSharp.IRestResponse<T> re2)
        {
            if (re2.IsSuccessful)
            {
                return re2.Data;
            }
            if (re2.ErrorException != null)
            {
                throw re2.ErrorException;
            }
            else
                throw new ArgumentException("请求失败:" + re2.ErrorMessage + "," + re2.Content);
        }


        public ExchangeInformation ExchangeInformation => throw new NotImplementedException();

        public IDictionary<string, object> PositionSide => throw new NotImplementedException();

        public IList<AccountBalance> Balance => throw new NotImplementedException();

        public AccountInformation AccountInformation => throw new NotImplementedException();

        public IList<PositionRisk> PositionRisk => throw new NotImplementedException();

        public IDictionary<string, object> addIsolatedPositionMargin(string symbolName, int type, string amount, PositionSide positionSide)
        {
            throw new NotImplementedException();
        }

        public IList<object> batchCancelOrders(string symbol, string orderIdList, string origClientOrderIdList)
        {
            throw new NotImplementedException();
        }

        public ResponseResult cancelAllOpenOrder(string symbol)
        {
            throw new NotImplementedException();
        }

        public com.binance.client.model.trade.Order cancelOrder(string symbol, long? orderId, string origClientOrderId)
        {
            throw new NotImplementedException();
        }

        public Leverage changeInitialLeverage(string symbol, int? leverage)
        {
            throw new NotImplementedException();
        }

        public ResponseResult changeMarginType(string symbolName, string marginType)
        {
            throw new NotImplementedException();
        }

        public ResponseResult changePositionSide(bool dual)
        {
            throw new NotImplementedException();
        }

        public string closeUserDataStream(string listenKey)
        {
            throw new NotImplementedException();
        }

        public IList<PriceChangeTicker> get24hrTickerPriceChange(string symbol)
        {
            throw new NotImplementedException();
        }

        public IList<MyTrade> getAccountTrades(string symbol, long? startTime, long? endTime, long? fromId, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<AggregateTrade> getAggregateTrades(string symbol, long? fromId, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<com.binance.client.model.trade.Order> getAllOrders(string symbol, long? orderId, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<Candlestick> getCandlestick(string symbol, CandlestickInterval interval, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<FundingRate> getFundingRate(string symbol, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<CommonLongShortRatio> getGlobalAccountRatio(string symbol, PeriodType period, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<Income> getIncomeHistory(string symbol, IncomeType incomeType, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<LiquidationOrder> getLiquidationOrders(string symbol, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<MarkPrice> getMarkPrice(string symbol)
        {
            throw new NotImplementedException();
        }

        public IList<com.binance.client.model.market.Trade> getOldTrades(string symbol, int? limit, long? fromId)
        {
            throw new NotImplementedException();
        }

        public IList<OpenInterestStat> getOpenInterestStat(string symbol, PeriodType period, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<com.binance.client.model.trade.Order> getOpenOrders(string symbol)
        {
            throw new NotImplementedException();
        }

        public com.binance.client.model.trade.Order getOrder(string symbol, long? orderId, string origClientOrderId)
        {
            throw new NotImplementedException();
        }

        public OrderBook getOrderBook(string symbol, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<WalletDeltaLog> getPositionMarginHistory(string symbolName, int type, long startTime, long endTime, int limit)
        {
            throw new NotImplementedException();
        }

        public IList<com.binance.client.model.market.Trade> getRecentTrades(string symbol, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<SymbolOrderBook> getSymbolOrderBookTicker(string symbol)
        {
            throw new NotImplementedException();
        }

        public IList<SymbolPrice> getSymbolPriceTicker(string symbol)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                var re = CreateReq("fapi/v1/ticker/price", false, false).Get<SymbolPrice[]>();
                return re.Data;
            }
            else
            {
                var re = CreateReq("fapi/v1/ticker/price", false, false).AddParameter("symbol", symbol).Get<SymbolPrice>();
                return new[] { re.Data };
            }
        }

        public IList<TakerLongShortStat> getTakerLongShortRatio(string symbol, PeriodType period, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<CommonLongShortRatio> getTopTraderAccountRatio(string symbol, PeriodType period, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public IList<CommonLongShortRatio> getTopTraderPositionRatio(string symbol, PeriodType period, long? startTime, long? endTime, int? limit)
        {
            throw new NotImplementedException();
        }

        public string keepUserDataStream(string listenKey)
        {
            throw new NotImplementedException();
        }

        public IList<object> postBatchOrders(string batchOrders)
        {
            throw new NotImplementedException();
        }

        public com.binance.client.model.trade.Order postOrder(string symbol, com.binance.client.model.enums.OrderSide side, PositionSide positionSide, com.binance.client.model.enums.OrderType orderType, com.binance.client.model.enums.TimeInForce timeInForce, string quantity, string price, string reduceOnly, string newClientOrderId, string stopPrice, WorkingType workingType, NewOrderRespType newOrderRespType)
        {
            throw new NotImplementedException();
        }

        public string startUserDataStream()
        {
            throw new NotImplementedException();
        }
    }
}